package controllers

import (
	"github.com/kataras/iris/v12"
	"irisdemo/model"
	"irisdemo/service"
	"net/http"
)

var User = newUserController()

type userController struct {
}

func newUserController() *userController {
	return &userController{}
}

func (this *userController) Login(c iris.Context) {

	params := new(model.UserLogin)

	if err := c.ReadJSON(params); err != nil {
		c.JSON(iris.Map{"code": http.StatusBadGateway, "msg": "参数错误"})
		return
	}

	//验证数据, 暂无

	//调用服务
	flag := service.User.Login(params.Username, params.Password)

	if !flag {
		c.JSON(iris.Map{"code": http.StatusNotFound, "msg": "用户名/密码错误"})
		return
	}

	c.JSON(iris.Map{"code": http.StatusOK, "msg": "OK", "data": iris.Map{}})

}

func (this *userController) DelUser(c iris.Context) {

	//fmt.Printf("reqMap :  %#s", string(res))
	//fmt.Printf("reqMap :  %#v", c.Values())

	//uid := c.Values().GetString("uid")
	//fmt.Println(uid)

	c.JSON(iris.Map{"code": iris.StatusOK, "msg": "ok", "data": iris.Map{}})
}
